/*!
 * \file frproto_get_chklist.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frlist.h"
#include "frproto_mng.h"
#include "apmtest_cunit.h"

#include "apmtest_comm.h"

extern int g_i_flag_run;

static int __suite_init(void)
{
//    frmodule_mng_init();
    return 0;
}

static int __suite_cleanup(void)
{
//    frmodule_mng_destory();
    return 0;
}


typedef struct __st_proto_priority {
    u_short us_port_start;      /* port 开始 */
    u_short us_port_end;        /* port 结束 */

    Frmodule_mng *p_module_mng;
} Frproto_priority;

typedef struct __st_param_priority {
    Frlist_header *p_lst_hdr;

    int i_ip_proto;
    u_short us_port1;
    u_short us_port2;
} Frparam_priority;

int __list_node_pri_get_chklist(Frlist_node *p_st_node_in, const void *p_data);

static void __case1(void)
{
    Frlist_node* p_st_node = NULL;
    Frlist_header *p_lst_hdr_pri = NULL;
    Frlist_header *p_lst_hdr_general = NULL;
    Frmodule_mng *p_module_mng_node = NULL;
    int i_ip_proto = 6;
    u_short us_port1 = 40;
    u_short us_port2 = 80;
    int i_ret = 0;

    //p_lst_hdr_pri
    p_lst_hdr_pri = frlist_create();
    p_lst_hdr_general = frlist_create();

    //p_module_mng_node
    p_module_mng_node = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng_node, 0x00, sizeof(Frmodule_mng));
    p_module_mng_node->i_is_stub = FR_NO;
    p_module_mng_node->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng_node->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng_node->p_st_l7_module->i_l7_proto = 1;
    p_module_mng_node->p_st_l7_module->us_l4_proto = 6;

    p_st_node = frlist_node_create(p_module_mng_node);
    frlist_add_tail(p_lst_hdr_pri,p_st_node);
    frlist_add_tail(p_lst_hdr_general,p_st_node);

    frproto_mng_init();
    i_ret = frproto_get_chklist(i_ip_proto, us_port1, us_port2, p_lst_hdr_pri, p_lst_hdr_general);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    // frlist_remove_all(p_lst_hdr_pri,NULL);
    //  frlist_remove_all(p_lst_hdr_pri,NULL);
    frfree(p_module_mng_node->p_st_l7_module);
    frfree(p_module_mng_node);
    frfree(p_lst_hdr_pri);
    frfree(p_lst_hdr_general);
    frproto_mng_destory();

    return;

}

int add_suite_frproto_get_chklist(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frproto_mng frproto_get_chklist()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
//    CU_add_test(pSuite, "case2", __case2);
//    CU_add_test(pSuite, "case3", __case3);
//    CU_add_test(pSuite, "case4", __case4);
//    CU_add_test(pSuite, "case5", __case5);

    return FR_SUCC;
}
